package com.example.service.serviceImpl;

import com.example.entity.po.Test;
import com.example.entity.vo.PaginationResultVO;
import com.example.enums.PageSize;
import com.example.entity.query.SimplePage;
import com.example.entity.query.TestQuery;
import com.example.service.TestService;
import com.example.mapper.TestMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:测试表 业务接口
 * 
 * @Date:2024/07/12
 */
@Service("testService")
public class TestServiceImpl implements TestService {

	@Resource
	private TestMapper<Test, TestQuery> testMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Test> findListByParam(TestQuery query) {
		return this.testMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	@Override
	public Integer findCountByParam(TestQuery query) {
		return this.testMapper.selectCount(query);
	}

	/**
	 * 分页查询
	 */
	@Override
	public PaginationResultVO<Test> findListByPage(TestQuery query) {
		Integer count = this.findCountByParam(query);
		Integer pageSize = query.getPageSize() == null ? PageSize.SIZE15.getSize() : query.getPageSize();
		SimplePage page = new SimplePage(query.getPageNo(), count, pageSize);
		query.setSimplePage(page);
		List<Test> list = this.findListByParam(query);
		PaginationResultVO<Test> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */

	@Override
	public Integer add(Test bean) {
		return this.testMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<Test> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.testMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增/修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<Test> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.testMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 根据IdAndUserId查询
	 */
	@Override
	public Test getTestByIdAndUserId (Integer id, Integer userId) {
		return this.testMapper.selectByIdAndUserId(id, userId);
	}

	/**
	 * 根据IdAndUserId修改
	 */
	@Override
	public Integer updateTestByIdAndUserId(Test bean, Integer id, Integer userId) {
		return this.testMapper.updateByIdAndUserId(bean, id, userId);
	}

	/**
	 * 根据IdAndUserId删除
	 */
	@Override
	public Integer deleteTestByIdAndUserId(Integer id, Integer userId) {
		return this.testMapper.deleteByIdAndUserId(id, userId);
	}


	/**
	 * 根据NikName查询
	 */
	@Override
	public Test getTestByNikName (String nikName) {
		return this.testMapper.selectByNikName(nikName);
	}

	/**
	 * 根据NikName修改
	 */
	@Override
	public Integer updateTestByNikName(Test bean, String nikName) {
		return this.testMapper.updateByNikName(bean, nikName);
	}

	/**
	 * 根据NikName删除
	 */
	@Override
	public Integer deleteTestByNikName(String nikName) {
		return this.testMapper.deleteByNikName(nikName);
	}

}